/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package station3d.math;

/**
 * Vektor v trojrozměrném prostoru.
 * @author Martin
 */
public class Vector3D {

    public double x;
    public double y;
    public double z;

    public Vector3D() {
        x = 0; y = 0; z = 0;
    }

    public Vector3D(Vector3D v) {
        this(v.x, v.y, v.z);
    }

    public Vector3D(double x, double y, double z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public void setTo(Vector3D v) {
        this.x = v.x;
        this.y = v.y;
        this.z = v.z;
    }

    public void setTo(double x, double y, double z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public void add(double x, double y, double z) {
        this.x += x;
        this.y += y;
        this.z += z;
    }

    public void add(Vector3D v) {
        add(v.x, v.y, v.z);
    }

    public void subtract(double x, double y, double z) {
        this.x -= x;
        this.y -= y;
        this.z -= z;
    }

    public void subtract(Vector3D v) {
        subtract(v.x, v.y, v.z);
    }

    public void multiply(double k) {
        this.x *= k;
        this.y *= k;
        this.z *= k;
    }

    public void divide(double k) {
        this.x /= k;
        this.y /= k;
        this.z /= k;
    }

    public double size() {
        return Math.sqrt(x*x + y*y + z*z);
    }

    public void unit() {
        divide(size());
    }

    public static Vector3D add(Vector3D a, Vector3D b) {
        return new Vector3D(a.x + b.x, a.y + b.y, a.z + b.z);
    }

    public static Vector3D subtract(Vector3D a, Vector3D b) {
        return new Vector3D(a.x - b.x, a.y - b.y, a.z - b.z);
    }

    public static Vector3D multiply(double k, Vector3D v) {
        return new Vector3D(k*v.x, k*v.y, k*v.z);
    }

    public static Vector3D multiply(Vector3D v, double k) {
        return new Vector3D(k*v.x, k*v.y, k*v.z);
    }

    public static Vector3D divide(Vector3D v, double k) {
        return new Vector3D(v.x/k, v.y/k, v.z/k);
    }

    public static Vector3D unit(Vector3D v) {
        Vector3D v2 = new Vector3D(v);
        v2.unit();
        return v2;
    }


    public static Vector3D normal2D(Vector3D v) {
        return new Vector3D(-v.z, v.y, v.x);
    }



    @Override
    public String toString() {
        return x + "; " + y + "; " + z;
    }

}
